package com.business_clean.viewmodel.request

import androidx.lifecycle.MutableLiveData
import com.business_clean.app.App
import com.business_clean.app.config.Constant
import com.business_clean.app.network.NetUrl
import com.business_clean.data.mode.address.AddressEntity
import com.business_clean.data.mode.camera.LeaderClockEntity
import com.business_clean.data.mode.circle.ChatStatEntity
import com.business_clean.data.mode.classes.ClassesEntity
import me.hgj.mvvmhelper.base.BaseViewModel
import me.hgj.mvvmhelper.ext.rxHttpRequest
import me.hgj.mvvmhelper.net.LoadingType
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

//拍照相关内容
class CameraViewModel : BaseViewModel() {

    var uploadState = MutableLiveData<Any>()

    var settingState = MutableLiveData<Any>()

    var leaderClockEntity = MutableLiveData<LeaderClockEntity>()

    var addressManager = MutableLiveData<AddressEntity>()

    var check = MutableLiveData<Any>()


    /**
     * 标记
     */
    fun requestMarkPhoto(hashMap: HashMap<String, String>, showDialog: Boolean) {
        rxHttpRequest {
            onRequest = {
                uploadState.value = RxHttp.get(NetUrl.MARK_PHOTO)
                    .addAll(hashMap)
                    .toResponse<Any>().await()
            }
            loadingType = if (showDialog) LoadingType.LOADING_CUSTOM else LoadingType.LOADING_NULL
        }
    }


    /**
     * 员工的设置
     */
    fun requestPhotoSetting(hashMap: HashMap<String, String>) {
        rxHttpRequest {
            onRequest = {
                settingState.value = RxHttp.get(NetUrl.CAMERA_SETTING)
                    .addAll(hashMap)
                    .toResponse<Any>().await()
            }
            loadingType = LoadingType.LOADING_NULL
        }
    }


    /**
     * 获取默认出勤配置
     */
    fun requestAttendance() {
        rxHttpRequest {
            onRequest = {
                leaderClockEntity.value = RxHttp.get(NetUrl.CAMERA_ATTENDANCE_INFO)
                    .add("project_uuid", App.appViewModelInstance.projectInfo.value?.uuid)
                    .toResponse<LeaderClockEntity>().await()
            }
        }
    }


    /**
     * 获取当前项目的打卡地点
     */
    fun requestAddressAll() {
        rxHttpRequest {
            onRequest = {
                addressManager.value = RxHttp.get(NetUrl.GET_ADDRESS_ALL)
                    .add("page", "1")
                    .add("size", Constant.PAGE_SIZE)
                    .add("project_uuid", App.appViewModelInstance.userInfo.value?.project?.uuid)
                    .toResponse<AddressEntity>().await()
            }
            loadingType = LoadingType.LOADING_NULL
        }
    }


    /**
     * 查询当前地址和时间是否可打卡
     */
    fun requestCheckClockAddress(lnt: Double, lat: Double) {
        rxHttpRequest {
            onRequest = {
                check.value = RxHttp.get(NetUrl.CHECK_CLOCK_ADDRESS)
                    .add("lnt", "$lnt")
                    .add("lat", "$lat")
                    .toResponse<Any>().await()
            }
            loadingType = LoadingType.LOADING_NULL
        }
    }

}